# Maintainer: George Rawlinson <grawlinson@archlinux.org>
# Contributor: Wesley Moore <wes@wezm.net>
set -x

pkgbase=pastel
pkgname=('pastel' 'pastel-docs')
pkgver=0.9.0
pkgrel=1
pkgdesc='A command-line tool to generate, analyze, convert and manipulate colors'
arch=('loong64' 'x86_64')
url='https://github.com/sharkdp/pastel'
license=('MIT' 'Apache')
makedepends=('git' 'rust')
_commit='47f9ddd59ea14df8d9d1f1073d14501751a49fd0'
source=("$pkgbase::git+$url.git#commit=$_commit")
b2sums=('SKIP')

pkgver() {
  cd "$pkgbase"
  git describe --tags | sed "s/^v//"
}

prepare() {
  cd "$pkgbase"

  # download dependencies
  rm -f Cargo.lock
  cargo fetch --target "$CARCH-unknown-linux-gnu"
}

build() {
  cd "$pkgbase"
  SHELL_COMPLETIONS_DIR="$PWD/completions" cargo build --release #--frozen
}

check() {
  cd "$pkgbase"
  cargo test --frozen
}

package_pastel() {
  depends=('gcc-libs')
  cd "$pkgbase"

  # binary
  install -vDm755 -t "$pkgdir/usr/bin" "target/release/$pkgname"

  # shell completions
  install -vDm644 completions/_pastel \
    "$pkgdir/usr/share/zsh/site-functions/_pastel"
  install -vDm644 completions/pastel.bash \
    "$pkgdir/usr/share/bash-completion/completions/pastel"
  install -vDm644 completions/pastel.fish \
    "$pkgdir/usr/share/fish/vendor_completions.d/pastel.fish"

  # licenses
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE*
}

package_pastel-docs() {
  pkgdesc+=' (documentation)'
  depends=('bash')

  cd "$pkgbase"
  
  # documentation
  install -vDm644 -t "$pkgdir/usr/share/doc/$pkgname" ./*.md
  cp -vr doc "$pkgdir/usr/share/doc/$pkgname"

  # licenses
  install -vDm644 -t "$pkgdir/usr/share/licenses/$pkgname" LICENSE*
}
